function varargout = wfd_gui(varargin)
% WFD_GUI MATLAB code for wfd_gui.fig
%      WFD_GUI, by itself, creates a new WFD_GUI or raises the existing
%      singleton*.
%
%      H = WFD_GUI returns the handle to a new WFD_GUI or the handle to
%      the existing singleton*.
%
%      WFD_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in WFD_GUI.M with the given input arguments.
%
%      WFD_GUI('Property','Value',...) creates a new WFD_GUI or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before wfd_gui_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to wfd_gui_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help wfd_gui

% Last Modified by GUIDE v2.5 18-Nov-2011 14:18:28

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @wfd_gui_OpeningFcn, ...
    'gui_OutputFcn',  @wfd_gui_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before wfd_gui is made visible.
function wfd_gui_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to wfd_gui (see VARARGIN)

% Choose default command line output for wfd_gui
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes wfd_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = wfd_gui_OutputFcn(hObject, eventdata, handles)
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit_p_Callback(hObject, eventdata, handles)
% hObject    handle to edit_p (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_p as text
%        str2double(get(hObject,'String')) returns contents of edit_p as a double
p=get(hObject,'String');
b=num2str(str2double(p)/2);
if ~get(handles.check_hb,'value')
    set(handles.edit_hb,'string',b);
end
if ~get(handles.check_vb,'value')
    set(handles.edit_vb,'string',b);
end

UpdateWH(handles);


% --- Executes during object creation, after setting all properties.
function edit_p_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_p (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_yp_Callback(hObject, eventdata, handles)
% hObject    handle to edit_yp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_yp as text
%        str2double(get(hObject,'String')) returns contents of edit_yp as a double
yp=get(hObject,'String');
ye=num2str(str2double(yp)/2);
if ~get(handles.check_vb,'value')
    set(handles.edit_vb,'string',ye);
end
UpdateWH(handles);

% --- Executes during object creation, after setting all properties.
function edit_yp_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_yp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_r_Callback(hObject, eventdata, handles)
% hObject    handle to edit_r (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_r as text
%        str2double(get(hObject,'String')) returns contents of edit_r as a double
UpdateWH(handles);


% --- Executes during object creation, after setting all properties.
function edit_r_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_r (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_hb_Callback(hObject, eventdata, handles)
% hObject    handle to edit_hb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_hb as text
%        str2double(get(hObject,'String')) returns contents of edit_hb as a double
hb=get(hObject,'String');
if ~get(handles.check_vb,'value')
    set(handles.edit_vb,'string',hb);
end

% --- Executes during object creation, after setting all properties.
function edit_hb_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_hb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_w_Callback(hObject, eventdata, handles)
% hObject    handle to edit_w (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_w as text
%        str2double(get(hObject,'String')) returns contents of edit_w as a double


% --- Executes during object creation, after setting all properties.
function edit_w_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_w (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_xe_Callback(hObject, eventdata, handles)
% hObject    handle to edit_hb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_hb as text
%        str2double(get(hObject,'String')) returns contents of edit_hb as a double
xe=get(hObject,'String');
if ~get(handles.check_vb,'value')
    set(handles.edit_vb,'string',xe);
end
UpdateWH(handles);

% --- Executes during object creation, after setting all properties.
function edit_xe_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_hb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_vb_Callback(hObject, eventdata, handles)
% hObject    handle to edit_vb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_vb as text
%        str2double(get(hObject,'String')) returns contents of edit_vb as a double
UpdateWH(handles);

% --- Executes during object creation, after setting all properties.
function edit_vb_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_vb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_n_Callback(hObject, eventdata, handles)
% hObject    handle to edit_n (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_n as text
%        str2double(get(hObject,'String')) returns contents of edit_n as a double
UpdateWH(handles);

% --- Executes during object creation, after setting all properties.
function edit_n_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_n (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit_nr_Callback(hObject, eventdata, handles)
% hObject    handle to edit_nr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit_nr as text
%        str2double(get(hObject,'String')) returns contents of edit_nr as a double
UpdateWH(handles);

% --- Executes during object creation, after setting all properties.
function edit_nr_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_nr (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in push_submit.
function push_submit_Callback(hObject, eventdata, handles)
% hObject    handle to push_submit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes on button press in check_w.
function check_w_Callback(hObject, eventdata, handles)
% hObject    handle to check_w (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of check_w
if get(hObject,'Value')
    set(handles.edit_w,'enable','on');
else
    set(handles.edit_w,'enable','off');
end

% --- Executes on button press in check_hb.
function check_hb_Callback(hObject, eventdata, handles)
% hObject    handle to check_hb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of check_hb
if get(hObject,'Value')
    set(handles.edit_hb,'enable','on');
else
    set(handles.edit_hb,'enable','off');
end

% --- Executes on button press in check_vb.
function check_vb_Callback(hObject, eventdata, handles)
% hObject    handle to check_vb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of check_vb
if get(hObject,'Value')
    set(handles.edit_vb,'enable','on');
else
    set(handles.edit_vb,'enable','off');
end


% --- Executes on button press in check_hb.
function check_xe_Callback(hObject, eventdata, handles)
% hObject    handle to check_hb (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of check_hb
if get(hObject,'Value')
    set(handles.edit_hb,'enable','on');
else
    set(handles.edit_hb,'enable','off');
end

% --- Executes on button press in check_yp.
function check_yp_Callback(hObject, eventdata, handles)
% hObject    handle to check_yp (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of check_yp
if get(hObject,'Value')
    set(handles.edit_yp,'enable','on');
else
    set(handles.edit_yp,'enable','off');
end


function [W,H]=UpdateWH(handles)
r=str2double(get(handles.edit_r,'string'));
n=str2double(get(handles.edit_n,'string'));
p=str2double(get(handles.edit_p,'string'));
hb=str2double(get(handles.edit_hb,'string'));
vb=str2double(get(handles.edit_vb,'string'));
W=(n-1)*p+2*hb;
H=2*vb;
set(handles.edit_h,'string',num2str(H));
set(handles.edit_w,'string',num2str(W));


% --- Executes on button press in push_plot.
function push_plot_Callback(hObject, eventdata, handles)
% hObject    handle to push_plot (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
UpdateWH(handles)
r=str2double(get(handles.edit_r,'string'));
n=str2double(get(handles.edit_n,'string'));
p=str2double(get(handles.edit_p,'string'));
hb=str2double(get(handles.edit_hb,'string'));
vb=str2double(get(handles.edit_vb,'string'));
SetData(r,n,p,hb,vb)
figure%axes(handles.axs_show);
PlotHole;
PlotCrack;


% --- Executes on button press in push_close.
function push_close_Callback(hObject, eventdata, handles)
% hObject    handle to push_close (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes during object creation, after setting all properties.
function edit_h_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit_h (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in check_h.
function check_h_Callback(hObject, eventdata, handles)
% hObject    handle to check_h (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of check_h
